package fpeas.either;

import fpeas.function.Function;

public class EitherUtility
{
	public static <A,B> Either<A,B> left(final A left)
	{
		return new Either<A,B>()
		{
			public <R> R visit(final Function<? super A, ? extends R> ifA, final Function<? super B, ? extends R> ifB)
			{
				return ifA.run(left);
			}
		};
	}

	public static <A,B> Either<A,B> right(final B right)
	{
		return new Either<A,B>()
		{
			public <R> R visit(final Function<? super A,? extends R> ifA,final Function<? super B,? extends R> ifB)
			{
				return ifB.run(right);
			}
		};
	}

	public static <A,B> Function<A,Either<A, B>> left()
	{
		return new Function<A,Either<A,B>>()
		{
			public Either<A, B> run(final A a)
			{
				return left(a);
			}
		};
	}

	public static <A,B> Function<B,Either<A,B>> right()
	{
		return new Function<B,Either<A,B>>()
		{
			public Either<A,B> run(final B b)
			{
				return right(b);
			}
		};
	}
}